<?php
/**
 * @author jim
 * @date 2017/12/5/005
 *
 */

namespace app\admin\model;
use think\Model;

class CompanyAuthModel extends Model
{
    protected $connection = 'JS_SERVE';
    protected $table = 'company_auth';
    protected $resultSetType = 'collection';

    //查询单条记录
    public function findData($where, $column = '*', $order = [])
    {
        if ($order)
            $data = self::where($where)->field($column)->order($order)->find();
        else
            $data = self::where($where)->field($column)->find();
        $data ? $data = $data->toArray() : '';
        return $data;
    }

    //查询多条记录
    public function selectData($where, $column = '*', $order = [])
    {
        if ($order)
            $data = self::where($where)->field($column)->order($order)->select()->toArray();
        else
            $data = self::where($where)->field($column)->select()->toArray();
        return $data;
    }

    //更新记录
    public function editData($where, $data)
    {
        $re = $this->save($data, $where);
        return $re;
    }

    //添加
    public function addData($data)
    {
        $this->data($data);
        $this->isUpdate(false)->save();
        return $this->getLastInsID();
    }

    //删除数据
    public function delData($where)
    {
        $this->destroy($where);
    }

    //筛选数据
    public function searchData($param, $page, $pernum, $order = ['id' => 'desc'])
    {
        if ($pernum)
            $data = self::where($param)->order($order)->limit($pernum)->page($page)->select()->toArray();
        else
            $data = self::where($param)->order($order)->select()->toArray();
        return $data;
    }

    //获取总数
    public function getTotalNum($param)
    {
        return self::where($param)->count();
    }

    //获取和
    public function sumData($param, $field)
    {
        return self::where($param)->sum($field);
    }

    public function queryData($sql)
    {
        $list = self::query($sql);
        return $list;
    }

}
